//
//  MWFilterMenuCell.m
//  XiRan-iOS
//
//  Created by liuyiming on 2019/11/1.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWFilterMenuCell.h"

@interface MWFilterMenuCell ()

@property(nonatomic, strong) UIButton *titleBtn;

@end

@implementation MWFilterMenuCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self setupPageSubviews];
        
//        self.layer.borderColor = [[UIColor redColor] CGColor];
//        self.layer.borderWidth = 1;
    }
    return self;
}

- (void)onClickAction:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
    if(self.checkWithIndexPathBlock) {
        self.checkWithIndexPathBlock(self.indexPath);
    }
}

- (void)setTitle:(NSString *)title {
    [_titleBtn setTitle:title forState:UIControlStateNormal];
}

- (void)setIsSelected:(BOOL)isSelected {
    _titleBtn.selected = isSelected;
    if (isSelected) {
        _titleBtn.layer.borderColor = MWHexColor(@"#FD9F2B").CGColor;
    } else {
        _titleBtn.layer.borderColor = MWHexColor(@"#E7E7E7").CGColor;
    }
}

- (void)setupPageSubviews {
    _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    _titleBtn.contentEdgeInsets = UIEdgeInsetsMake(10, 5, 10, 5);
    _titleBtn.layer.borderWidth = 0.5;
    _titleBtn.layer.borderColor = MWHexColor(@"#E7E7E7").CGColor;
    _titleBtn.titleLabel.font = MWFont(12);
    _titleBtn.titleLabel.lineBreakMode = 0;
    [_titleBtn setTitleColor:MWHexColor(@"#333333") forState:UIControlStateNormal];
    [_titleBtn setTitleColor:MWHexColor(@"#FD9F2B") forState:UIControlStateSelected];
    [_titleBtn setTitle:@"胡桃木" forState:UIControlStateNormal];
    [_titleBtn addTarget:self action:@selector(onClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_titleBtn];
    
    [_titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.right.lessThanOrEqualTo(self.contentView.mas_right);
        make.centerY.equalTo(self.contentView);
    }];
}

- (void)setItemButtonBackgroundColor:(UIColor *)color
{
    self.titleBtn.backgroundColor = color;
}

@end
